﻿using System;
using System.Diagnostics.Contracts;

namespace Isuka.Iteration.Auxiliaries
{
    internal sealed class AnonymousIterable<TIterator>
        : IIterable<TIterator>
        where TIterator : IIterator
    {
        readonly Func<TIterator> begin;
        readonly Func<TIterator> end;

        public AnonymousIterable(Func<TIterator> begin, Func<TIterator> end)
        {
            Contract.Requires<ArgumentNullException>(begin != null, "begin");
            Contract.Requires<ArgumentNullException>(end != null, "end");

            this.begin = begin;
            this.end = end;
        }

        #region IIterable<TIterator> メンバー

        public TIterator Begin()
        {
            return Gate.NotNull(begin());
        }

        public TIterator End()
        {
            return end();
        }

        #endregion
    }
}
